import {mapGetters} from 'vuex'
import {receivePage} from '../api/acceptance'
let moment = require('moment')

export default {
    name: 'project-manage-list',
    computed: {
        ...mapGetters(['permissions'])
    },
		provide () {
			return {
				initList: this.getListData
			};
		},
    mounted() {
        this.edit_but = this .permissions['proacceptance_edit']
        this.belongs = this.getDict('belongs')
        this.manageUnits = this.getDict('administrative_office')
        this.projectType = this.getDict('project_types')
        this.getListData()
    },
    data() {
        return {
					// 请求参数
					params: {
						current: 1,
						size: 20,
						projectName: ""
					},
					// 选中的数据
					selectDataArr: [],
					// 分页
					pager: {
						total: 0, // 总页数
						current: 1, // 当前页数
						size: 20 // 每页显示多少条
					},
					// 页面loading
					loading: false,
          belongs: [],
          manageUnits: [],
          projectType:[],
          edit_but: false,
          placeholder: '输入项目名称',
          tableData: [],
          queryData: {
              projectName: ''
          },
          NewIcon: require('@/assets/images/new.png'), //new图标
        }
    },
    methods: {
			getListData (params = {}) {
				this.loading = true;
				let requestData = {...this.params, ...params};
				receivePage(requestData)
					.then(res => {
						const {current, size, total, records} = res.data.data;
						this.tableData = records;
						this.params = requestData;
						this.pager = {total, current, size};
					})
					.finally(() => {
						this.loading = false;
					});
			},
        // hxf-0903-完善信息
        handlePerfectInformation(data) {
            console.log(data)
            this.$router.push({name: 'acceptance_edit', query:{projectId: data.projectId}})
        },
        // hxf-0903-查询权限
        handleQueryPermissions() {},
        // hxf-0903-竣工时间
        dateFormat: function(row, column, cellValue){
            if(!cellValue){
                return ''
            }
            return moment(cellValue).format('YYYY-MM-DD')
        },
        // hxf-0903-物业权属
        formateBelong: function(row, column, cellValue){
            let obj = this.manageUnits.find(p => p.value == cellValue)
            if(obj){
                return obj.label
            }
            return ''
        },
        formateProjectType: function(row, column, cellValue){
            let obj = this.projectType.find(p => p.value == cellValue)
            if(obj){
                return obj.label
            }
            return ''
        },
    }
}
